package TAIC.util ;
import java.util.* ;
import java.io.*; 
import java.nio.channels.*  ;

class CopyVOC {

	static public void main ( String s [] ) {
		if ( s.length != 2 ) {
			System.out.println ( "Please input file name, image_dir_name" ) ;
			return ;
		}
		try {
			Scanner scanner = new Scanner ( new File ( s [ 0 ] ) ) ;
			int count = 0 ;
			PrintStream fout = new PrintStream ( new File ( s [ 1 ] + "\\index.txt" ) ) ; 
			( new File ( s [ 1 ] + "\\" )).mkdirs () ; 
			while ( scanner.hasNext () && count < 71 ) {
				String temp = scanner.next() ;
				if ( scanner.next ().equals ( "1" ) ) {
					fout.println ( temp + ".png" ) ; 
					copyFile ( "..\\PNGImages\\" + temp + ".png" , s [ 1 ] + "\\" + temp + ".png" ) ;
					count ++ ; 
				}
			}
		}
		catch ( Exception e ) {
			e.printStackTrace () ; 
		}
	}
	
	public static boolean copyFile( String a , String b ) //  Source and Destination
    {
    	boolean done= true ;
		File in = new File ( a );
		File out = new File ( b ) ;
		FileChannel inChannel = null;
		FileChannel outChannel = null;
        try {
    	
        inChannel = new
            FileInputStream(in).getChannel();
        outChannel = new
            FileOutputStream(out).getChannel();
            inChannel.transferTo(0, inChannel.size(),
                    outChannel);
        } 
        catch (IOException e) {
            //e.printStackTrace () ;
            done =  false ;
        }
        finally {           
			return done ;
        }
    }	
}